#include "UdpServe.hpp"
#include <memory>
#include "InetAddr.hpp"
#include "Route.hpp"
#include "PthreadPool.hpp"
#include <functional>
using funcpopl = std::function<void()>;
using namespace PthreadModlue;
std::string defaultfunc(std::string messges)
{
    return messges;
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cerr << "Usage: " << argv[0] << " port" << std::endl;
        return 1;
    }
    ENABLE_CONSOLE_LOG_STRATEGY();
    uint16_t port = std::stoi(argv[1]);

    // 1.创建route对象提供吧消息转发给所有的在线用户
    Route r;
    
    // 2.创建线程池
    auto pt = PthreadPoolModule::PthreadPool<funcpopl>::GetInstance();
     pt->Start();
    std::unique_ptr<UdpServe> udpserveptr = std::make_unique<UdpServe>(port, [&r, &pt](int sockfd, std::string message, InetAddr peer){
        funcpopl fun=std::bind(&Route::RouteMessage,&r,sockfd,message,peer);
        pt->Enqueue(fun);
    });
    udpserveptr->Init();
    udpserveptr->Start();
    return 0;
}